package com.lyf.baoxian.utils;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.text.format.DateFormat;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lyf.baoxian.R;

import java.util.Calendar;

/**
 * Created by 刘亚飞 on 2016/11/30.
 */

public class MyMethod {
    /**
     * 设置标题
     * @param activity
     * @param title:标题内容
     */
    public static void setTitle(final Activity activity, String title){
        ImageView imageView = (ImageView) activity.findViewById(R.id.every_top_back);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
        TextView textView = (TextView) activity.findViewById(R.id.every_top_title);
        textView.setText(title);

        Button button = (Button) activity.findViewById(R.id.bt_right);

    }


    /**
     * 设置带右侧按钮的标题
     * @param activity
     * @param title
     * @param btText
     */
    public static void setTitle(final Activity activity, String title,String btText,View.OnClickListener onClickListener){
        ImageView imageView = (ImageView) activity.findViewById(R.id.every_top_back);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
        TextView textView = (TextView) activity.findViewById(R.id.every_top_title);
        textView.setText(title);

        Button button = (Button) activity.findViewById(R.id.bt_right);
        button.setVisibility(View.VISIBLE);
        button.setText(btText);
        button.setOnClickListener(onClickListener);
    }

    public static void setTitle(final Activity activity, String title,View.OnClickListener onClickListener){
        ImageView imageView = (ImageView) activity.findViewById(R.id.every_top_back);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.finish();
            }
        });
        TextView textView = (TextView) activity.findViewById(R.id.every_top_title);
        textView.setText(title);

        ImageView imSelect = (ImageView) activity.findViewById(R.id.every_top_img);
        imSelect.setVisibility(View.VISIBLE);
        imSelect.setOnClickListener(onClickListener);
    }



    /**
     * 时间选择对话框
     * @param context
     * @param editText
     */
    public static void showDateDiaog(Context context, final TextView editText){
        final Calendar c = Calendar.getInstance();
        DatePickerDialog dialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                c.set(year,monthOfYear,dayOfMonth);
                editText.setText(DateFormat.format("yyyy-MM-dd", c));
            }
        },c.get(Calendar.YEAR),c.get(Calendar.MONTH),c.get(Calendar.DAY_OF_MONTH));
        dialog.show();
    }

    /**
     *
     * @param tv1 选中的TextView
     * @param tv2 未选中的TextView
     * @param tv3 未选中的TextView
     * @param tv4 未选中的TextView
     */
    public static void setColor(TextView tv1,TextView tv2,TextView tv3,TextView tv4){
        tv1.setBackgroundResource(R.color.home_tab);
        tv2.setBackgroundResource(R.color.white);
        tv3.setBackgroundResource(R.color.white);
        tv4.setBackgroundResource(R.color.white);
    }
}
